package org.example.springchatroom.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.springchatroom.model.Friend;
import org.example.springchatroom.model.MessageSession;
import org.example.springchatroom.model.MessageSessionUser;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/9/6
 * Time: 18:11
 */
@Mapper
public interface MessageSessionMapper {
    @Select("select session_id from message_session where session_id in (select session_id from message_session_user where user_id = #{userId}) order by last_time desc")
    List<Integer> getSessionIdList(Integer userId);

    @Select("select user_id as friendId,user_name as friendName from user where user_id in (select user_id from message_session_user where session_id = #{sessionId} and user_id != #{selfUserId})")
    List<Friend> getFriendListBySessionId(Integer sessionId,Integer selfUserId);

    Integer addMessageSession(MessageSession messageSession);

    @Insert("insert into message_session_user values (#{sessionId},#{userId})")
    Integer addMessageSessionUser(MessageSessionUser messageSessionUser);
}
